<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> 讨论</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">

    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 150px;
            margin-top: 3px
        }
    </style>
</head>
<body class="gray-bg">
<span id="gloUrl" style="display: none"></span>
<div class="wrapper wrapper-content  animated fadeInRight article">
    <div class="row">
        <div class="col-lg-10 col-lg-offset-1">
            <div class="ibox">
                <div class="evaluateA" style="margin-top: 5px;text-align: right" data-toggle="modal" data-target="#myModal">
                    <a class="animated bounceInUp"  href="javascript:void(0)" title="评论">
                    <button class="btn btn-success">发表你的评论</button></a>
                </div>
                <div class="ibox-content">

                </div>
            </div>
        </div>
    </div>

</div>
<!--弹出框-->
<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 300px;overflow-y: scroll">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <h4 class="modal-title">评论讨论</h4>
            </div>
            <div class="formListAdd" align="center">
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label for="comment">评论内容</label>
                        <textarea id="comment" rows="5" placeholder="请输入评论内容......（不要超过200字）" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmEva">发表评论</button>
            </div>
        </div>
    </div>
</div>
<!--回复弹出框-->
<div class="modal inmodal" id="myModalRes" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 300px;overflow-y: scroll">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <h4 class="modal-title">评论讨论</h4>
            </div>
            <div class="formListAdd" align="center">
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label for="commentRes">回复内容</label>
                        <textarea id="commentRes" rows="5" placeholder="请输入回复内容......（不要超过200字）" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmRes">发表评论</button>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- 自定义js -->
<script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
<!--    分页js -->
<!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
<script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/static/js/GloJs.js"></script>


<script>
    //判断当前页面是否在iframe中

        var evaluateA = '';
        $('body').append(evaluateA);

    $(function (){
        let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
        let Glo_user = localStorage.getItem("userId")
        //获取讨论
        function getDetail(){
            let html_dom = $(".ibox-content")
            $.ajax({
                url: Glo_BaseUrl + "/tArticle/detail",
                type: "get",
                data: {
                    applyer:Glo_user,
                    id:localStorage.getItem("id")
                },
                success: function (data) {
                    let evaluateStr = ``
                    for (let i = 0; i < data.Data.evaluateList.length; i++) {
                        let item = data.Data.evaluateList[i]
                        let childEvaluateStr = ``
                        let FSpecialStr = `<a href="javascript:void(0)" data-toggle="modal" data-target="#myModalRes" class="communicate" thisId="${item.senderId}" landlordId="${item.landlordId}" style="margin-left: 50px">回复Ta</a>
`
                        if (item.senderId + "" === Glo_user){//如果发送者跟当前登录人一致，则 没有 回复Ta 按钮，因为不能回复自己！
                            FSpecialStr = ``
                        }
                        for (let j = 0; j < item.childEvaluate.length; j++) {
                            let itemChild = item.childEvaluate[j]
                            let specialStr = ` <a href="javascript:void(0)" data-toggle="modal" data-target="#myModalRes" class="communicate" landlordId="${item.landlordId}" thisId="${itemChild.senderId}" style="margin-left: 50px">回复Ta</a>`
                            if (itemChild.senderId + "" === Glo_user){//如果发送者跟当前登录人一致，则 没有 回复Ta 按钮，因为不能回复自己！
                                specialStr = ``
                            }
                            childEvaluateStr +=`  <div  style="transform: translateX(50px)">
                                    <div class="social-avatar">
                                        <a href="javascript:void(0)" class="pull-left">
                                            <img alt="image" src="${item.receiverImg}">
                                        </a>
                                        <div class="">
                                            <a href="javascript:void(0)">
                                                ${itemChild.senderName}
                                            </a>

 &nbsp;回复&nbsp;
                                             <a href="javascript:void(0)">
                                                 ${itemChild.receiverName}
                                            </a>
                                            <small class="text-muted"> ${itemChild.createTime}</small>
                                        </div>
                                    </div>
                                    <div class="social-body">
                                        <p style="transform: translateX(20px)">
                                            ${itemChild.comment}
                                            `+specialStr+`
                                        </p>
                                    </div>

                                </div>`
                        }
                        evaluateStr +=`<div class="social-feed-box">
                                    <div class="social-avatar">
                                        <a href="javascript:void(0)" class="pull-left">
                                            <img alt="image" src="${item.senderImg}">
                                        </a>
                                        <div class="media-body">
                                            <a href="javascript:void(0)">
                                                ${item.senderName}
                                            </a>
                                            <small class="text-muted"> ${item.createTime}</small>
                                        </div>
                                    </div>
                                    <div class="social-body" style="padding: 25px">
                                        <p style="transform: translateX(20px)">
                                            ${item.comment}
                                            `+FSpecialStr+`
                                        </p>
                                    </div>

                                 `+childEvaluateStr+`
                                </div>`
                    }
                    let fileName = "暂无文件"
                    let fileNameBtn = ``
                    if (data.Data.fileName != null){
                        fileName = data.Data.fileName
                        fileNameBtn = ` <a href="/tFile/download?id=${data.Data.fileId}" class="btn btn-info btn-sm">点此<i class="fa fa-download"></i>下载(${data.Data.downloadTimes})</a>`
                    }
                    let Str =` <div class="pull-right">
                        <button class="btn btn-white btn-xs" type="button">标签 ： ${data.Data.typeName}</button>


                    </div>
                    <div class="pull-left">
                    讨论附件：
                    <span style="color: #5da9ea;font-size: 1.2rem">`+
                        fileName+
                        `

</span>
                 `+fileNameBtn+`
</div>
                    <div class="text-center article-title">
                        <h1>
                          ${data.Data.title}
                        </h1>
                    </div>
                    ${data.Data.content}
                    <hr>
                        <div class="row">
                            <div class="col-lg-12">

                                <h2>评论：</h2>
                       `+evaluateStr+`
`+`  </div>
                        </div>`
                    if (data.code !== 500) {
                        html_dom.html("")
                        html_dom.append(Str)
                    } else {
                        alert("获取失败")
                    }

                    //回复评论
                    $(".communicate").click(function (){
                        let receiverId = $(this).attr("thisId")
                        let landlordId = $(this).attr("landlordId")
                        let id = localStorage.getItem("id")
                        $("#confirmRes")
                            .attr("receiverId",receiverId)
                            .attr("landlordId",landlordId)

                    })

                    //确认回复评论
                    $("#confirmRes").click(function (){
                        let receiverId = $(this).attr("receiverId")
                        let landlordId = $(this).attr("landlordId")
                        let id = localStorage.getItem("id")

                        $.ajax({
                            url: Glo_BaseUrl + "/tComment/add",
                            type: "post",
                            data: {
                                recriverId: receiverId,
                                senderId:Glo_user,
                                comment:$("#commentRes").val(),
                                originFlag:"0",
                                landlordId:landlordId,
                                articleId:id,
                                resFlag:"Y"
                            },
                            success: function (data) {
                                if (data.code === 200){
                                    swal(data.msg,"回复成功", "success");
                                }else {
                                    swal(data.msg,"回复失败", "error");
                                }

                                getDetail(2)
                            },
                            error: function () {
                                alert("服务器异常！network error！")
                            }
                        })
                    })
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            });


        }
        getDetail()
        //发表评论
        $("#confirmEva").click(function (){
            let id = localStorage.getItem("id")
            $.ajax({
                url: Glo_BaseUrl + "/tComment/add",
                type: "post",
                data: {
                    articleId: id,
                    status:1,
                    senderId:Glo_user,
                    comment:$("#comment").val(),
                    originFlag:"1",
                    landlordId:Glo_user
                },
                success: function (data) {
                    if (data.code === 200){
                        swal(data.msg,"评论成功", "success");
                    }else {
                        swal(data.msg,"评论失败", "error");
                    }

                    getDetail(2)
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })
    })
</script>




</body>
</html>
